package com.example.demo.config;

import com.example.demo.config.constant.ResponseCode;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.auth.AuthenticationException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.io.IOException;

/**
 * @Author: 聂吉泽
 * @Description:
 * @Date: create in 2021/11/10 8:55
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(IllegalArgumentException.class)
    public ResponseWrapper illegalArgumentException(IllegalArgumentException e){
        return ResponseWrapper.fail();
    }

    @ExceptionHandler(IOException.class)
    public ResponseWrapper ioException(IOException e){
        return ResponseWrapper.fail();
    }

    @ExceptionHandler(AuthenticationException.class)
    public ResponseWrapper authentication(AuthenticationException e){
        return ResponseWrapper.fail(ResponseCode.UNAUTHORIZED);
    }
}
